package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.bean.CheckBean;
import com.dingwei.lesyndrome.bean.SelectedMerchantsBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.MathUtil;
import com.lihao.baselibrary.utils.ScreenUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/7.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class SelectedMerchantsAdapter extends RecyclerArrayAdapter<SelectedMerchantsBean.DataBean.ListBean> {
    public SelectedMerchantsAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new SelectedMerchantsHolder(parent);
    }


    public class SelectedMerchantsHolder extends BaseViewHolder<SelectedMerchantsBean.DataBean.ListBean> {


        @Bind(R.id.img)
        ImageView img;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_look)
        TextView tvLook;
        @Bind(R.id.tv_distance)
        TextView tvDistance;
        @Bind(R.id.layout)
        LinearLayout layout;

        public SelectedMerchantsHolder(ViewGroup parent) {
            super(parent, R.layout.item_selected_merchants);
            ButterKnife.bind(this, itemView);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,(ScreenUtils.getScreenWidth(BaseActivity.context)-48)/2/5*3);
            img.setLayoutParams(lp);

        }

        @Override
        public void setData(SelectedMerchantsBean.DataBean.ListBean data) {
            super.setData(data);
            Glide.with(BaseActivity.context)
                    .load(data.img)
                    .apply(MyApplication.options)
                    .into(img);
            tvName.setText(data.title);
            tvLook.setText(data.views+"");
            if (data.distance>1000){
                tvDistance.setText(MathUtil.getTwoNum(data.distance/1000)+"km");
            }else {
                tvDistance.setText(MathUtil.getTwoNum(data.distance)+"m");
            }
        }
    }
}
